package com.o2o.app.userCenter;

import com.o2o.app.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class UserInfoSexActivity extends Activity {
	// 性别
	private static int FORUSERITEMSEX = 5558;
	/**
	 * title标签
	 */
	private TextView tv_title;

	/**
	 * 保存按钮
	 */
	private Button btn_pass;

	/**
	 * 返回按钮
	 */
	private Button btn_back;

	/**
	 * 是否保密
	 */
	private CheckBox parking_info;

	/**
	 * 性别布局
	 */
	private RadioGroup radioGroupSex;
	private RadioButton radioMale, radioFemale;

	/**
	 * 判断是男女
	 */
	private String et_sex = "0"; // 0是男，1是女

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_sex);

		initViews();
		initData();
	}

	private void initViews() {
		// 标题
		tv_title = (TextView) findViewById(R.id.tv_title);

		// 是否保密
		parking_info = (CheckBox) findViewById(R.id.parking_info);

		// 返回
		btn_back = (Button) findViewById(R.id.btn_back);
		btn_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		// 保存
		btn_pass = (Button) findViewById(R.id.btn_pass);
		btn_pass.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.putExtra("secrecy", parking_info.isChecked());
				intent.putExtra("sex", et_sex);
				setResult(FORUSERITEMSEX, intent);
				finish();
			}
		});

		radioGroupSex = (RadioGroup) findViewById(R.id.radioGroupSex);
		// 男女按钮组监听事件
		radioGroupSex.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// 根据ID判断选择的按钮
				if (checkedId == R.id.radioMale) {
					et_sex = "0";
				} else {
					et_sex = "1";
				}
			}
		});

		radioMale = (RadioButton) findViewById(R.id.radioMale);
		radioFemale = (RadioButton) findViewById(R.id.radioFemale);
	}

	private void initData() {
		tv_title.setText(getIntent().getStringExtra("title"));

		if ("男".equals(getIntent().getStringExtra("info"))) {
			radioMale.setChecked(true);
			radioFemale.setChecked(false);
		} else {
			radioMale.setChecked(false);
			radioFemale.setChecked(true);
		}
	}
}
